// Saver.h
#ifndef SAVER_H
#define SAVER_H

#include <string>
#include "Item.h"
#include "json.hpp"  

using json = nlohmann::json;

class Player;
class Character;
class StatusEffect;
class Skill;
class Item;
class BackPack;
class Equipment;

class Saver {
public:
    // 保存游戏进度到文件
    static bool saveGame(const Player& player, const std::string& filename);

    // 从文件加载游戏进度
    static bool loadGame(Player& player, const std::string& filename);

private:
    // 序列化辅助函数
    static void serializePlayer(const Player& player, json& j);
    static void serializeStatusEffects(const std::vector<StatusEffect>& effects, json& j);
    static void serializeSkills(const std::vector<Skill>& skills, json& j);
    static void serializeBackpack(const BackPack& backpack, json& j);
    static void serializeItem(Item* item, json& j);
    static void serializeEquipment(Equipment* equip, json& j);

    // 反序列化辅助函数
    static void deserializePlayer(const json& j, Player& player);
    static void deserializeStatusEffects(const json& j, std::vector<StatusEffect>& effects);
    static void deserializeSkills(const json& j, std::vector<Skill>& skills);
    static void deserializeBackpack(const json& j, BackPack& backpack);
    static Item* deserializeItem(const json& j);
    static Equipment* deserializeEquipment(const json& j);
};

#endif // SAVER_H
